<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <?php
        include_once ('../includes/utilidades.php');
        include_once ('../includes/html.php');
        session_start();
        
        $target_dir = "./";
        //print_r($_FILES);
        $target_file = $target_dir . basename($_FILES["fichero"]["name"]);
        $uploadOk = 1;
        $imageFileType = pathinfo($target_file, PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
        /*
          if (isset($_POST["submit"])) {
          $check = getimagesize($_FILES["fichero"]["tmp_name"]);
          if ($check !== false) {
          echo "File is an image - " . $check["mime"] . ".";
          $uploadOk = 1;
          } else {
          echo "File is not an image.";
          $uploadOk = 0;
          }
          }
         */

        //print $target_file;
        if (move_uploaded_file($_FILES["fichero"]["tmp_name"], $target_file)) {
            echo "El fichero " . basename($_FILES["fichero"]["name"]) . " se ha subido correctamente<br>";
        } else {
            echo "Error cargando el fichero " . $_FILES["fichero"]["name"];
        }
        
        $temporada = select2("select * from temporada order by fechainicio");
        $club = select2("select * from club order by nombre");
        print "<form name=import method=post action=checkImportAtletas.php>\n";
        print "Club:<select name=idclub>\n";
        foreach ($club as $c) {
            print "<option value=" . $c['id'] . ">" . $c['nombre'] . "</option>\n";
        }
        print "</select>";
        
        print "<br>Temporada:<select name=idtemporada>\n";
        foreach ($temporada as $t) {
            print "<option value=" . $t['id'] . ">" . $t['nombre'] . "</option>\n";
        }
        print "</select>\n";
        
        $text="";
        $handle = fopen($target_file, "r");
        if ($handle) {
            while (($line = fgets($handle)) !== false) {
                //print $line . "<br>" . "\n";
                $text .= $line;
            }
        } else {
            // error opening the file.
        }
        fclose($handle);
        
        print "<br>Datos:<br><textarea name=atletas rows=20 cols=80>\n" . $text . "</textarea>\n";
        print "<input type=submit value=Enviar>";
        print "</form>\n";
        ?>
    </body>
</html>
